package com.usian.article.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.api.article.AuthorControllerApi;
import com.usian.article.service.AuthorService;
import com.usian.article.service.impl.AuthorServiceImpl;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/v1/author")
public class AuthorController implements AuthorControllerApi {

    @Autowired
    private AuthorServiceImpl service;

    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id") Integer id){
        return service.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(id!=null,ApAuthor::getUserId,id));
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody ApAuthor apAuthor){
         if (apAuthor==null)return service.errorParam;
         service.save(apAuthor);
        return service.success;
    }

    @Override
    @RequestMapping
    public ApAuthor findById(Integer id) {
        return service.getById(id);
    }

}